#!/bin/env python
# -*- coding:utf-8
"""
@author:xingz
@file:Connectfour_ai.py
@time:2021/11/18
"""
from minmax import find_best_move
from connectfour.Connectfour import C4Board, C4Board2
from board import Move, Board

board = C4Board2()


def get_player_move() -> Move:
    player_move = Move(-1)
    while player_move not in board.legal_moves:
        play_x: int = int(input("Enter a legal column:"))
        play_y: int = int(input("Enter a legal row:"))
        player_move = (Move(play_x), Move(play_y))
    return player_move


if __name__ == '__main__':
    print(board)
    while True:
        # human_move = get_player_move()
        human_move = find_best_move(board, 2)
        board = board.move(human_move)
        print("Human turn:")
        print(board)
        if board.is_win:
            print("Human wins!!")
            break
        if board.is_draw:
            print("Draw!!")
            break
        compute_move = find_best_move(board, 2)
        board = board.move(compute_move)
        print("Compute turn:")
        print(board)
        if board.is_win:
            print("Computer wins!!")
            break
        elif board.is_draw:
            print("Draw!!")
            break
